CFLAGS=-g
CC=gcc

OPENSSL_DIR?=openssl-0.9.6
OPENSSL_BIN=$(OPENSSL_DIR)/libssl.a

PROG=update-cache show-diff init-db write-tree read-tree commit-tree cat-file

all: $(PROG) $(OPENSSL_DIR)/libssl.a

install: $(PROG)
	install $(PROG) $(HOME)/bin/

OPENSSL_LIB=$(OPENSSL_BIN) $(OPENSSL_DIR)/libcrypto.a $(OPENSSL_DIR)/libRSAglue.a
INC=-I$(OPENSSL_DIR)/include
LIB=-lz

$(OPENSSL_BIN):
	file $@

init-db: init-db.o

update-cache: update-cache.o read-cache.o $(OPENSSL_BIN)
	$(CC) $(CFLAGS) -o update-cache update-cache.o read-cache.o $(INC) $(OPENSSL_LIB) $(LIB)

show-diff: show-diff.o read-cache.o $(OPENSSL_BIN)
	$(CC) $(CFLAGS) -o show-diff show-diff.o read-cache.o $(INC) $(OPENSSL_LIB) $(LIB)

write-tree: write-tree.o read-cache.o $(OPENSSL_BIN)
	$(CC) $(CFLAGS) -o write-tree write-tree.o read-cache.o $(INC) $(OPENSSL_LIB) $(LIB)

read-tree: read-tree.o read-cache.o $(OPENSSL_BIN)
	$(CC) $(CFLAGS) -o read-tree read-tree.o read-cache.o $(INC) $(OPENSSL_LIB) $(LIB)

commit-tree: commit-tree.o read-cache.o $(OPENSSL_BIN)
	$(CC) $(CFLAGS) -o commit-tree commit-tree.o read-cache.o $(INC) $(OPENSSL_LIB) $(LIB)

cat-file: cat-file.o read-cache.o $(OPENSSL_BIN)
	$(CC) $(CFLAGS) -o cat-file cat-file.o read-cache.o $(INC) $(OPENSSL_LIB) $(LIB)

read-cache.o: cache.h
show-diff.o: cache.h

clean:
	rm -f *.o $(PROG) temp_git_file_*

backup: clean
	cd .. ; tar czvf dircache.tar.gz dir-cache
